package visao.turma;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import modelagem.Aluno;
import modelagem.Curso;
import modelagem.Professor;
import visao.aluno.BuscadeAlunos;

import com.towel.swing.table.ObjectTableModel;

import controle.Curso.cursoDAO;
import controle.aluno.alunoDAO;
import controle.professor.professorDAO;
import controle.turma.AcoesInterfaceTurma;

@SuppressWarnings("serial")
public class interfaceTurma extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JButton btnSalvar;
	private JButton btnCancelar;
	private JTable tableAlunMat;
	private ObjectTableModel<Aluno> modeloTabela, modeloTabAlunDaTurma;
	private JComboBox<String> comboBoxProf;
	private JComboBox<String> comboBoxCurso;
	private AcoesInterfaceTurma AcoesInterfaceTurma;
	private JLabel lblCodigoDaTurma;
	private JTextField textCodigo;
	private JTextArea textArea;
	private JTable tableAlunNaTurma;
	private JButton btnAdd;
	private JButton btnVisualizarTurmas;

	/**
	 * Launch the application.
	 
	public static void main(String[] args) {
		try {
			interfaceTurma dialog = new interfaceTurma();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

	/**
	 * Create the dialog.
	 */
	public interfaceTurma() {
		this.setBounds(100, 100, 505, 400);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setModal(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		AcoesInterfaceTurma = new AcoesInterfaceTurma(this);
		
		JLabel lblProfessor = new JLabel("Professor:");
		lblProfessor.setBounds(10, 11, 66, 14);
		contentPanel.add(lblProfessor);
		
		ArrayList<Professor> profList = (ArrayList<Professor>) new professorDAO().buscar(""); 
		comboBoxProf = new JComboBox<String>();
		comboBoxProf.addItem("Selecione um professor");
		for(int i = 0; i < profList.size(); i++){
			comboBoxProf.addItem(profList.get(i).getNome());
		}
		comboBoxProf.setBounds(86, 7, 191, 20);
		contentPanel.add(comboBoxProf);
		
		modeloTabela = new BuscadeAlunos(null).getModeloTabela();
		modeloTabela.addAll(new alunoDAO().buscar("", ""));
		tableAlunMat = new JTable(modeloTabela);
		
		tableAlunMat.getColumnModel().getColumn(0).setPreferredWidth(100);
		tableAlunMat.getColumnModel().getColumn(1).setPreferredWidth(300);
		
		JScrollPane scrollPane = new JScrollPane(tableAlunMat);
		scrollPane.setBounds(234, 169, 253, 162);
		contentPanel.add(scrollPane);
		
		JLabel lblAlunosMatriculados = new JLabel("Alunos matriculados:");
		lblAlunosMatriculados.setBounds(206, 144, 125, 14);
		contentPanel.add(lblAlunosMatriculados);
		
		JLabel lblCurso = new JLabel("Curso:");
		lblCurso.setBounds(10, 35, 46, 14);
		contentPanel.add(lblCurso);
		
		
		ArrayList<Curso> cursoList = (ArrayList<Curso>) new cursoDAO().buscar(""); 
		comboBoxCurso = new JComboBox<String>();
		comboBoxCurso.addItem("Selecione um curso");
		for(int i = 0; i < profList.size(); i++){
			comboBoxCurso.addItem(cursoList.get(i).getNome());
		}
		comboBoxCurso.setBounds(63, 31, 140, 20);
		contentPanel.add(comboBoxCurso);
		
		lblCodigoDaTurma = new JLabel("C\u00F3digo da turma:");
		lblCodigoDaTurma.setBounds(294, 8, 109, 14);
		contentPanel.add(lblCodigoDaTurma);
		
		textCodigo = new JTextField();
		textCodigo.setBounds(401, 5, 86, 20);
		contentPanel.add(textCodigo);
		textCodigo.setColumns(10);
		
		textArea = new JTextArea();
		textArea.setLineWrap(true);
		textArea.setBounds(10, 81, 477, 55);
		contentPanel.add(textArea);
		
		JLabel lblObservacoes = new JLabel("Observacoes:");
		lblObservacoes.setBounds(10, 61, 86, 14);
		contentPanel.add(lblObservacoes);
		
		modeloTabAlunDaTurma = new BuscadeAlunos(null).getModeloTabela();
		modeloTabAlunDaTurma.clear();
		
		tableAlunNaTurma = new JTable(modeloTabAlunDaTurma);
		tableAlunNaTurma.setBounds(0, 0, 277, 1);
		tableAlunNaTurma.getColumnModel().getColumn(0).setPreferredWidth(50);
		tableAlunNaTurma.getColumnModel().getColumn(1).setPreferredWidth(300);
		contentPanel.add(tableAlunNaTurma);
		
		JScrollPane scrollPane2 = new JScrollPane(tableAlunNaTurma);
		scrollPane2.setBounds(10, 169, 193, 162);
		contentPanel.add(scrollPane2);
		
		
		
		JLabel lblAlundaTurm = new JLabel("Alunos adicionados:");
		lblAlundaTurm.setBounds(10, 144, 125, 14);
		contentPanel.add(lblAlundaTurm);
		
		btnAdd = new JButton("<<");
		btnAdd.addActionListener(AcoesInterfaceTurma);
		btnAdd.setBounds(192, 228, 51, 36);
		contentPanel.add(btnAdd);
		{
			JPanel buttonPane = new JPanel();
			FlowLayout fl_buttonPane = new FlowLayout(FlowLayout.CENTER);
			fl_buttonPane.setHgap(50);
			buttonPane.setLayout(fl_buttonPane);
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				btnSalvar = new JButton("Salvar");
				btnSalvar.addActionListener(AcoesInterfaceTurma);
				btnSalvar.setActionCommand("OK");
				buttonPane.add(btnSalvar);
				getRootPane().setDefaultButton(btnSalvar);
			}
			{
				btnCancelar = new JButton("Cancelar");
				btnCancelar.addActionListener(AcoesInterfaceTurma);
				btnCancelar.setActionCommand("Cancel");
				buttonPane.add(btnCancelar);
			}
			
			btnVisualizarTurmas = new JButton("Visualizar Turmas");
			btnVisualizarTurmas.addActionListener(AcoesInterfaceTurma);
			buttonPane.add(btnVisualizarTurmas);
		}
	}

	public JButton getBtnSalvar() {
		return btnSalvar;
	}
	public JButton getBtnCancelar() {
		return btnCancelar;
	}
	public JComboBox<String> getComboBoxProf() {
		return comboBoxProf;
	}
	public JComboBox<String> getComboBoxCurso() {
		return comboBoxCurso;
	}
	public JTextArea getTextArea() {
		return textArea;
	}
	public JTextField getTextCodigo() {
		return textCodigo;
	}
	public JButton getBtnAdd() {
		return btnAdd;
	}

	public JTable getTableAlunMat() {
		return tableAlunMat;
	}

	public JTable getTableAlunNaTurma() {
		return tableAlunNaTurma;
	}
	public JButton getBtnVisualizarTurmas() {
		return btnVisualizarTurmas;
	}

	public ObjectTableModel<Aluno> getModeloTabAlunDaTurma() {
		return modeloTabAlunDaTurma;
	}

	public ObjectTableModel<Aluno> getModeloTabela() {
		return modeloTabela;
	}

	public AcoesInterfaceTurma getAcoesInterfaceTurma() {
		return AcoesInterfaceTurma;
	}
}
